# Maintainer: Sébastien "Seblu" Luttringer
# Contributor: Le_suisse <lesuisse.dev+aur at gmail dot com>
# Contributor: Jason Rodriguez <jason-aur@catloaf.net>

pkgname=sslh
_pkgver=1.22c
# Remember: 1.22a < 1.22b < 1.22
pkgver=1.22.c
pkgrel=2
pkgdesc='SSL/SSH/OpenVPN/XMPP/tinc port multiplexer'
arch=('loong64' 'x86_64')
url='https://www.rutschle.net/tech/sslh/README.html'
license=('GPL2')
makedepends=('systemd')
depends=('glibc' 'libcap' 'libconfig' 'pcre2' 'systemd-libs')
backup=('etc/sslh.cfg')
install=$pkgname.install
source=("https://www.rutschle.net/tech/sslh/$pkgname-v$_pkgver.tar.gz"{,.asc}
        'sslh.cfg'
        'sslh.service'
        'sslh-select.service'
        'sslh-fork.service')
validpgpkeys=('CDDDBADBEA4B72748E007D326C056F7AC7934136') # Yves Rutschle <yves@rutschle.net>
sha256sums=('8e3742d14edf4119350cfdc7bb96b89134d9218eb6d2a6e1f70891ca18a649b1'
            'SKIP'
            '3feff7e2c096bc18d8f0073141c1017dccd4abbbc491fa16b55afd5c5ff6352c'
            '49ed1c88b0de079bc31a94e600b63edd7ea95b4aa9b5f533c15db1221d0892db'
            '885dfa4a4de75e28d0471debcb0473ecaf813eb21b83db4e855caf76a6d5cb3b'
            '46114de034266ea953eecb825730e4382faa8a97718f23df2a3ab2189623eb00')

prepare() {
  cd $pkgname-v$_pkgver
  # apply patch from the source array (should be a pacman feature)
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done
}

build() {
  cd $pkgname-v$_pkgver
  make VERSION=\"v$pkgver\" USELIBCAP=1 USESYSTEMD=1 all systemd-sslh-generator
}

package() {
  # default arch config
  install -Dm 644 sslh.cfg "$pkgdir/etc/sslh.cfg"
  # manually install to have both ssl-fork and ssl-select
  cd $pkgname-v$_pkgver
  install -Dm 755 sslh-fork "$pkgdir/usr/bin/sslh-fork"
  install -Dm 755 sslh-select "$pkgdir/usr/bin/sslh-select"
  ln -s sslh-fork "$pkgdir/usr/bin/sslh"
  # install manpage
  install -Dm 644 sslh.8.gz "$pkgdir/usr/share/man/man8/sslh.8.gz"
  ln -s sslh.8.gz "$pkgdir/usr/share/man/man8/sslh-fork.8.gz"
  ln -s sslh.8.gz "$pkgdir/usr/share/man/man8/sslh-select.8.gz"
  # install examples files
  install -Dm 644 basic.cfg "$pkgdir/usr/share/doc/$pkgname/basic.cfg"
  install -Dm 644 example.cfg "$pkgdir/usr/share/doc/$pkgname/example.cfg"
  # systemd
  install -dm 755 "$pkgdir"/usr/lib/systemd/{system,system-generators}
  install -Dm 755 systemd-sslh-generator "$pkgdir/usr/lib/systemd/system-generators/systemd-sslh-generator"
  cd "$pkgdir"
  install -Dm 644 "$srcdir"/sslh{,-fork,-select}.service usr/lib/systemd/system
}

# vim:set ts=2 sw=2 et:
